package com.zzj.utils;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class CodeGeneratorUtil {
    @Value("${spring.datasource.url}")
    private String url;
    @Value("${spring.datasource.username}")
    private String username;
    @Value("${spring.datasource.password}")
    private String password;

    public void codeGenerator() {
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("zzj")
                            .enableSpringdoc()
                            .commentDate("yyyy-MM-dd")
                            .outputDir("G:\\project\\z-cloud-disk-api\\src\\main\\java");  //制定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.zzj");
                })
                .strategyConfig(builder -> {
                    builder
//                            .addTablePrefix("")
                            .addInclude("file")
                            .addInclude("folder")
                            .addInclude("user")
                            .addInclude("log")


                            .entityBuilder()
                            .enableLombok()   //开启 Lombok
//                            .enableFileOverride() // 覆盖已生成entity文件

                            .controllerBuilder()
                            .enableRestStyle();
//                            .enableFileOverride(); // 覆盖已生成controller文件
                })
                .templateEngine(new FreemarkerTemplateEngine())// 模板引擎配置，默认 Velocity 可选模板引擎 Beetl 或 Freemarker
                .execute();
    }
}
